/*
 * Paper class for the Conference Application
 * Author: Jonathan Forbes
 * TCSS 360 Spring 2013 
 * University of Washington
 */

package Model;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Paper implements Serializable{
	
	/**
	 * Class that holds the Model of the Paper object, which contains all things pertinent to a
	 * specific paper, such as where the paper originated, who authored it, who the paper has been
	 * assigned to (Program Chair, SubProgram Chair, Reviewers), the conference the paper was
	 * submitted to, reviews that have been done on the paper, the paper's recommendation and
	 * rationale, the final acceptance decision for the paper, various string parameters pertinent
	 * to the paper, as well as the paper's content itself.
	 * 
	 * @author Jonathan Forbes
	 * @version 1.0
	 */
	private static final long serialVersionUID = 1L;

	private File filepath;
	
	private List<Review> reviews;
	
	private List<User> reviewers;
	
	private User SPC;
	
	private User Author;
	
	private Conference conference_submitted;
	
//	private Map<String, String> paper_parameters;
	private String[] paper_parameters;
	
	private String rationale;
	
	private int recommendation;
	
	private byte [] thePaperContent;
	
	// 0=undecided, 1=accepted, 2=rejected
	private int final_decision;
	
	private Date latest_revision;
	
	private int paper_unique_counter;
	
	// NOTICE: Some of these parameters are no longer needed: name, email, are both taken from the passed User Object
	// They have been left so as to not 
	public Paper(String filepath, String conference_category,
			     String paper_title, String keywords, String abstract_description,
			     Conference the_conference, User the_author) {
		
		paper_parameters = new String[]{conference_category, paper_title, keywords, abstract_description};
		this.filepath = new File(filepath);
		conference_submitted = the_conference;
		Author = the_author;
		reviews = new ArrayList<Review>();
		reviewers = new ArrayList<User>();
		final_decision = 0;
		latest_revision = new Date(); // automatically sets to the current date/time.
		recommendation = -1; //Means no rec given yet
		rationale = "";
	}
	
	public int getUniqueCode() {
		return paper_unique_counter;
	}
	
	public void setUniqueCode(int code) {
		paper_unique_counter = code;
	}
	
	public File getFilePath() {
		return filepath;
	}
	
	public void setFilePath(String filepath) {
		this.filepath = new File(filepath);
		latest_revision = new Date();
	}
	
	public void addReview(int directAndObvious, int broadOrNarrow, int significantOrNot,
			              int relevantRef, int teachingIntervantion, int goalMethods,
			              int replicateEvaluate, int wellWritten, int acceptedStandards,
			              int summaryRating, String comments, User reviewer) {
		Review new_review = new Review(directAndObvious, broadOrNarrow, significantOrNot,
				                       relevantRef, teachingIntervantion, goalMethods,
				                       replicateEvaluate, wellWritten, acceptedStandards,
				                       summaryRating, comments, reviewer);
		reviews.add(new_review);
	}
	
	public Review getReview(int index) {
		return reviews.get(index);
	}
	
	public int getNumberOfReviews() {
		return reviews.size();
	}
	
	public void addReviewer(User reviewer) {
		reviewers.add(reviewer);
	}
	
	public List<User> getReviewers() {
		return reviewers;
	}
	
	public int getNumberOfReviewers() {
		return reviewers.size();
	}
	
	public int getAcceptedStatus() {
		return final_decision;
	}
	
	public String getTitle() {
		return paper_parameters[1];
	}
	
	public String getCategory() {
		return paper_parameters[0];
	}
	
	// NOTICE: This method is depreciated, use getAuthor() instead
	public String getName() {
		return Author.getfullname();
	}
	
	// NOTICE: This method is depreciated, use getAuthor() instead
//	public String getAuthorEmail() {
//		return Author.getEmail();
//	}
	
	public String getRationale() {
		return rationale;
	}
	
	public int getRecommendation() {
		return recommendation;
	}
	
	public void setRecommendation(int recommendation) {
		this.recommendation = recommendation;
	}
	
	public void setRationale(String the_rationale) {
		rationale = the_rationale;
	}
	
	public User getAuthor() {
		return Author;
	}
	
	public User getSPC() {
		return SPC;
	}
	
	public void setSPC(User SPC) {
		this.SPC = SPC;
	}
	
	public Conference getConference() {
		return conference_submitted;
	}
	
	public void setAccepted(int decision) {
		final_decision = decision;
	}
	
	public Date getLatestRevision() {
		return latest_revision;
	}
	
	public void setLatestRevision(Date date) {
		latest_revision = date;
	}
	
	public void saveDigitalPaper(byte [] the_PaperContents) {
		thePaperContent = the_PaperContents;
	}
	
	public byte [] loadDigitalPaper() {
		return thePaperContent;
	}
	
	// We need some kind of unique identifier for papers, because every field in this Paper object currently could be the same and it could legitimately be a different paper.
	public boolean equals (Paper other_paper) {
		boolean result = true;
		return result;
	}
	
	//Ching-Ting
	public List<Review> getReviewList() {
		return reviews;
	} //getReviewList
	
	//Ching-Ting
	public void replaceReview(int directAndObvious, int broadOrNarrow, int significantOrNot,
			              int relevantRef, int teachingIntervantion, int goalMethods,
			              int replicateEvaluate, int wellWritten, int acceptedStandards,
			              int summaryRating, String comments, User reviewer, int index) {
		Review new_review = new Review(directAndObvious, broadOrNarrow, significantOrNot,
                relevantRef, teachingIntervantion, goalMethods,
                replicateEvaluate, wellWritten, acceptedStandards,
                summaryRating, comments, reviewer);
		reviews.set(index, new_review);
	} //removeOldReview
}


























